package com.example.work1month12begin.work.service.impl;

import com.example.work1month12begin.work.mapper.CityMapper;
import com.example.work1month12begin.work.mapper.CountryMapper;
import com.example.work1month12begin.work.pojo.City;
import com.example.work1month12begin.work.pojo.Country;
import com.example.work1month12begin.work.service.CityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CityServiceImpl implements CityService {

    @Autowired
    CityMapper mapper;

    @Autowired
    CountryMapper countryMapper;

    @Override
    public PageInfo<City> findPage(Integer pageNumber, Integer number) {
        PageHelper.startPage(pageNumber,number);
        List<City> cities = mapper.selectAll();
        for(City city:cities){
            Country country = countryMapper.selectById(city.getCityId());
            city.setCountry(country);
        }
        return new PageInfo<>(cities);
    }
}
